package com.lmonkey.servlet.cate;

import com.lmonkey.dao.Basedao;
import com.lmonkey.servic.CATAGORYDao;
import com.lmonkey.shop.CATEGORY;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet("/admin/admin_dousercate")
public class DouserCate extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //获取参数
        int fid = Integer.parseInt(request.getParameter("parentid"));
        String name = request.getParameter("classname");

        CATEGORY cate = new CATEGORY(0,name,fid);
        //连接数据库
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
         try{
             String sql = "insert into lmonkey_category values(null,?,?)";
             ps = conn.prepareStatement(sql);
             ps.setObject(1,cate.getCate_name());
             ps.setInt(2,cate.getCate_parent_id());
             ps.executeUpdate();
         }catch (SQLException e)
         {
             e.printStackTrace();
         }

        response.sendRedirect("admin_cateselect");
    }
}
